package com.xbongbong.saas.service;

import com.alibaba.fastjson.JSONObject;
import com.xbongbong.paas.domain.entity.PaasFormDataEntity;
import com.xbongbong.paas.domain.entity.ext.PaasFormDataEntityExt;
import com.xbongbong.paas.pojo.AssociatedBusinessAfterSavePojo;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.pojo.FieldAttrEntityForImport;
import com.xbongbong.paas.pojo.dto.FormDataAddDTO;
import com.xbongbong.paas.pojo.dto.FormDataListDTO;
import com.xbongbong.paas.pojo.dto.ImportFormDataDTO;
import com.xbongbong.paas.pojo.dto.SaasFormSaveDTO;
import com.xbongbong.paas.pojo.dto.ValidateDataDTO;
import com.xbongbong.paas.pojo.imports.CellTitlePojo;
import com.xbongbong.paas.pojo.imports.RowGroupPojo;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.pro.businessdata.pojo.dto.FormatExplainDTO;
import com.xbongbong.pro.businessproduct.pojo.dto.BusinessProductListDTO;
import com.xbongbong.pro.detailtab.dto.ChangeDocumentStatusSaveDTO;
import com.xbongbong.pro.detailtab.vo.ChangeDocumentStatusSaveVO;
import com.xbongbong.pro.detailtab.vo.ProductSummaryVO;
import com.xbongbong.pro.formexplain.pojo.dto.HandlerExplainInLinkItemDTO;
import com.xbongbong.pro.listbatch.pojo.dto.AddLabelDTO;
import com.xbongbong.pro.product.pojo.ProductSavePojo;
import com.xbongbong.pro.product.pojo.dto.PagingProductDTO;
import com.xbongbong.pro.product.pojo.vo.PagingProductVO;
import com.xbongbong.pro.returnedpurchase.pojo.dto.ReturnedPurchaseDeleteBatchDTO;
import com.xbongbong.pro.returnedpurchase.pojo.dto.ReturnedPurchaseEditAttrUpdateDTO;
import com.xbongbong.pro.returnedpurchase.pojo.dto.ReturnedPurchaseUpdateBatchDTO;
import com.xbongbong.pro.returnedpurchase.pojo.dto.ReturnedPurchaseUpdateByBusinessRuleDTO;
import com.xbongbong.pro.returnedpurchase.pojo.vo.ReturnedPurchaseDeleteBatchVO;
import com.xbongbong.pro.returnedpurchase.pojo.vo.ReturnedPurchaseUpdateBatchVO;
import com.xbongbong.saas.domain.entity.ReturnedPurchaseProductEntity;
import com.xbongbong.saas.domain.entity.ext.ReturnedPurchaseEntityExt;
import com.xbongbong.saas.enums.UpdateDataTypeEnum;

import java.util.List;
import java.util.Map;

/**
 * 采购退货单联系人service接口层
 *
 * @author Jian.Wang
 * @version v1.0
 * @date 2019/1/23 20:27
 * @since v1.0
 */
public interface ReturnedPurchaseService {
    /**
     * 采购退货单保存前saas特殊校验
     *
     * @param validateDataDTO saas特殊校验数据入参
     * @author Jian.Wang
     * @date 2019/1/23 20:00
     * @since v1.0
     **/
    void beforeSave(ValidateDataDTO validateDataDTO) throws XbbException;


    /**
     * 采购退货单保存后逻辑
     *
     * @param saasFormSaveDTO saas保存数据
     * @param newReturnedPurchaseEntityExt 新建成功的实体信息
     * @param associatedBusinessAfterSavePojo 关联新建发票、付款单相关信息
     * @author Jian.Wang
     * @date 2019/1/23 20:00
     * @since v1.0
     **/
    void afterSave(SaasFormSaveDTO saasFormSaveDTO, ReturnedPurchaseEntityExt newReturnedPurchaseEntityExt, AssociatedBusinessAfterSavePojo associatedBusinessAfterSavePojo) throws XbbException;



    /**
     * 新建时格式化解释
     *
     * @param formatExplainDTO 入参
     * @throws XbbException 异常
     */
    void formatAddExplain(FormatExplainDTO formatExplainDTO) throws XbbException;

    /**
     * 对采购退货单产品进行相关校验
     * @param returnedPurchaseProductList 采购退货产品数据
     * @param isNew 是否新建
     * @param corpid 公司ID
     * @param returnedPurchaseId 采购退货单ID
     * @date 2019/3/1 19:12
     * @author Jian.Wang
     */
    void checkReturnedPurchaseProduct(JSONObject returnedPurchaseProductList, boolean isNew, String corpid, Long returnedPurchaseId) throws XbbException;

    /**
     * 批量删除
     * @author 吴峰
     * @date 2019/3/8 10:55
     * @param returnedPurchaseDeleteBatchDTO
     * @return com.xbongbong.pro.returnedpurchase.pojo.vo.ReturnedPurchaseDeleteBatchVO
     * @throws XbbException 业务异常
     */
    ReturnedPurchaseDeleteBatchVO deleteBatch(ReturnedPurchaseDeleteBatchDTO returnedPurchaseDeleteBatchDTO) throws XbbException;

    /**
     * 批量更新
     * @author 吴峰
     * @date 2019/3/15 21:33
     * @param returnedPurchaseUpdateBatchDTO
     * @return com.xbongbong.pro.returnedpurchase.pojo.vo.ReturnedPurchaseUpdateBatchVO
     * @throws XbbException 业务异常
     */
    ReturnedPurchaseUpdateBatchVO updateBatch(ReturnedPurchaseUpdateBatchDTO returnedPurchaseUpdateBatchDTO) throws XbbException;

    /**
     * 批量更新
     * @author yuqian
     * @date 2019/3/15 21:33
     * @param returnedPurchaseUpdateBatchDTO
     * @return com.xbongbong.pro.returnedpurchase.pojo.vo.ReturnedPurchaseUpdateBatchVO
     * @throws XbbException 业务异常
     */
    ReturnedPurchaseUpdateBatchVO update(ReturnedPurchaseUpdateBatchDTO returnedPurchaseUpdateBatchDTO) throws XbbException;
    /**
     * 批量插入某个字段
     * @author 吴峰
     * @date 2019/3/20 15:30
     * @param returnedPurchaseEditAttrUpdateDTO
     * @return void
     * @throws XbbException 业务异常
     */
    void batchEditAttr(ReturnedPurchaseEditAttrUpdateDTO returnedPurchaseEditAttrUpdateDTO) throws XbbException;

    /**
     * 获取采购退货合同产品
     *
     * @param businessProductListDTO 入参
     * @param dataList data对象
     * @author chaoxiong.lei
     * @Date 14:37 2019/3/5
     * @since v1.0
     * @return BusinessProductListVO，属性product包含了单据关联产品，返回给前端的格式
     **/
//    BusinessProductListVO getReturnedPurchaseProductList(BusinessProductListDTO businessProductListDTO, JSONObject dataList) throws XbbException;

    /**
     * 关联新建格式化解释
     *
     * @param handlerExplainInLinkItemDTO 入参
     * @throws XbbException 异常
     */
    void formatLinkAddExplain(HandlerExplainInLinkItemDTO handlerExplainInLinkItemDTO) throws XbbException;

    /**
     * 将Excel数据格式化成表单保存需要的JSON格式的数据
     *
     * @param importFormDataDTO 导入入参
     * @param titlePojoList     标题
     * @param rowGroupPojo      一个表单对应的一组Excel填写的数据
     * @param fieldAttrList     解释
     * @return FormDataAddDTO
     * @throws XbbException XbbException
     * @author youli.chen
     * @date 2019/4/29 14:16
     * @since V1.0
     */
    FormDataAddDTO formatExcelValue(ImportFormDataDTO importFormDataDTO, List<CellTitlePojo> titlePojoList, RowGroupPojo rowGroupPojo, List<FieldAttrEntityForImport> fieldAttrList) throws XbbException;
    /**
     * 格式化导出值
     *
     * @param paasFormDataESList 数据
     * @throws XbbException 异常
     */
    void formatExportValue(List<PaasFormDataEntityExt> paasFormDataESList, FormDataListDTO formDataListDTO, List<FieldAttrEntityForImport> fieldAttrList) throws XbbException;

    /**
     * 汇总采购退货单产品信息（详情页，几种商品几件）
     *
     * @param businessProductListDTO 入参
     * @throws XbbException
     * @author long.rao
     * @date 2019-08-28 10:23
     */
    ProductSummaryVO summaryProductList(BusinessProductListDTO businessProductListDTO) throws XbbException;

    /**
     * 根据业务规则，更新采购退货
     * @author 吴峰
     * @date 2019/8/19 15:25
     * @param returnedPurchaseUpdateByBusinessRuleDTO
     * @return void
     * @throws XbbException 业务异常
     */
    void updateBatchByBusinessRule(ReturnedPurchaseUpdateByBusinessRuleDTO returnedPurchaseUpdateByBusinessRuleDTO) throws XbbException;

    void formatProduct4Show2(Long dataId, String corpid, JSONObject data, Boolean forProcess, Integer operate, UpdateDataTypeEnum updateDataTypeEnum) throws XbbException;

    PagingProductVO getPagingProduct(PagingProductDTO pagingProductDTO) throws XbbException;

    JSONObject formatSingleProduct(ReturnedPurchaseProductEntity entity, Boolean isEdit);

    /**
     * 出库单保存后判断是否出库完毕
     * @param outstockId
     * @param refId
     * @param corpid
     * @param productSavePojoList
     * @return
     */
    boolean judgeReturnPurchaseAllOutBound(Long outstockId, Long refId, String corpid, List<ProductSavePojo> productSavePojoList) throws XbbException;

    /**
     * 跟新采购退货开启关闭状态
     * @param changeDocumentStatusSaveDTO
     * @return
     */
    ChangeDocumentStatusSaveVO changeDocumentStatus(ChangeDocumentStatusSaveDTO changeDocumentStatusSaveDTO) throws XbbException;


    /**
     * 更新采购退货单中的发票ID
     * @param returnedPurchaseId 采购退货单ID
     * @param paasFormDataEntity 发票实体
     * @param saasFormSaveDTO 入参
     * @throws XbbException error
     * @author zhouwq
     * @date 2020/3/5 13:40
     */
    void updateReturnedPurchaseInvoiceId(Long returnedPurchaseId, PaasFormDataEntity paasFormDataEntity, SaasFormSaveDTO saasFormSaveDTO) throws XbbException;

    /**
     * 删除付款单更新采购退货退款中的合计退款金额
     * @param corpid 公司ID
     * @param delIdList 要删除的付款单id集合（不包含子付款单）
     * @param sheetIdToAmount 付款单id-付款金额（预付款核销要读取核销金额）
     * @author zhouwq
     * @date 2019/12/20 14:50
     * @update 2020/3/17 by zcp 依照退货退款相应方法copy改造为采购退货，需伟强检查确认
     */
    void updateRefund4Del(String corpid, List<Long> delIdList, Map<Long, Double> sheetIdToAmount) throws XbbException;

    /**
     * 供应商名称一致性同步
     * @param corpid 公司ID
     * @param supplierId 供应商id
     * @param supplierName 供应商名称
     * @throws XbbException
     * @since v1.0
     * @version v1.0
     */
    void dataConsistencyUpdateSupplier(String corpid, Long supplierId, String supplierName) throws XbbException;

    void formatBatchExplain(List<FieldAttrEntity> fieldAttrEntityList, String enable);

    /**
     * 批量增删标签
     * @param addLabelDTO
     * @param addBatchList
     * @throws XbbException
     */
    void updateBatchLabelAttr(AddLabelDTO addLabelDTO, List<PaasFormDataEntityExt> addBatchList, Boolean addOrDelete) throws XbbException;

    void afterSaveForWorkflow(SaasFormSaveDTO saasFormSaveDTO, ReturnedPurchaseEntityExt newReturnedPurchaseEntityExt, AssociatedBusinessAfterSavePojo associatedBusinessAfterSavePojo) throws XbbException;

    void afterSaveForUpdateWorkflow(SaasFormSaveDTO saasFormSaveDTO, ReturnedPurchaseEntityExt newReturnedPurchaseEntityExt, AssociatedBusinessAfterSavePojo associatedBusinessAfterSavePojo) throws XbbException;
}
